'use strict';

angular.module('snPaas_om').service('versionStore',['SpHttp','$q','baseUrl','Upload',function($http,$q,baseUrl,Upload){
	
	var getList = function(type){
		var deferred = $q.defer();
		$http.get('/rest/version/list',{params:{type:type}}).success(function(data,status){
			
			deferred.resolve(data.data);
		});
		return deferred.promise;
	};

	var addVersion = function(data){
		var deferred = $q.defer();
			Upload.upload({
				url:baseUrl.ajax+'/rest/version/add',
				data: {
					file:data.file
				}
			}).then(function (resp) {
				deferred.resolve(resp);
	        }, function (resp) {
	        	deferred.reject(resp);
	        }, function (evt) {
	        	deferred.notify(evt);
	        });


			return deferred.promise;
	};
	return {
		getList:getList,
		addVersion:addVersion
	};
}]);